package meforbio.wip.pint;

import java.util.Collection;

public class CooperativeAnd extends Cooperative{


	private String label; //juste informatif
	private Collection<Sorte> in;	
	private Collection<Sorte> out;
	//private Collection<Frappe> frappes;

	public CooperativeAnd(String label, Collection<Sorte> in, Collection<Sorte> out)
	{
		this.label = label;
		this.in = in;
		this.out = out;
		//System.err.println(id + ": "+ in + " -> " + out);
	}

	public String getLabel()
	{
		return label;
	}
	public String getFormula(Sorte so)
	{
		String result = "[";
		String eval = "[[";
		//System.err.println(id +" "+ in + " -> " + out);
		for (Sorte si : in)
		{
			result = result + ProcessHitting.addUnderscore(si.getId())+";";
			eval = eval + "1;";
		}
		eval = eval.substring(0,eval.length()-1) + "]]";
		result = result.substring(0,result.length()-1) + "] -> " + ProcessHitting.addUnderscore(so.getId()) + " 0 1, "+ eval;
		return result;
	}

	public String toString()
	{
		String result = "";
		result = result +  "(*"+this.getLabel()+"*)\n";
		for (Sorte so : out)
		{
			//System.out.println(so);
			result = result + "COOPERATIVITY("+ this.getFormula(so)+")\n";
		}
		return result;
	}
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((in == null) ? 0 : in.hashCode());
		result = prime * result + ((out == null) ? 0 : out.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CooperativeAnd other = (CooperativeAnd) obj;
		if (in == null) {
			if (other.in != null)
				return false;
		} else if (!in.equals(other.in))
			return false;
		if (out == null) {
			if (other.out != null)
				return false;
		} else if (!out.equals(other.out))
			return false;
		return true;
	}

	@Override
	public Collection<Sorte> getSortesSrc() {
		return in;
	}

	@Override
	public Collection<Sorte> getSortesDest() {
		return out;
	}
}
